package com.chanjet.donkey.jpa.annotation;

import org.hibernate.Session;
import org.hibernate.tuple.AnnotationValueGeneration;
import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.ValueGenerator;

public class ModifiedByValueGeneration implements AnnotationValueGeneration<ModifiedBy> {
	private ModifiedBy annotation;
	private long count = 1;
	private final ValueGenerator<?> generator = new ValueGenerator<Long>() {
		public Long generateValue(Session session, Object entity) {
			return count++;
		}
	};

	@Override
	public void initialize(ModifiedBy annotation, Class<?> propertyType) {
		this.annotation = annotation;
	}

	public GenerationTiming getGenerationTiming() {
		return annotation.value();
	}

	public ValueGenerator<?> getValueGenerator() {
		return generator;
	}

	public boolean referenceColumnInSql() {
		// not used -- needed only for in-DB generation
		return false;
	}

	public String getDatabaseGeneratedReferencedColumnValue() {
		// not used -- needed only for in-DB generation
		return null;
	}
}
